class Folder < Remote
  
  class << self
    def root
      find(:all, :from => :root)
    end
  
    def find_by_shares(id)
      find(:one, :from => "/folders/shares/#{id.to_s}.xml")
    end
  
    def search(query)
      find(:all, :from => "/folders/search/#{query}")
    end
  end
  
  def assets
    Asset.find(:all, :params => { :folder_id => id })
    # Asset.find(:all, :from => "/folders/#{id.to_s}/assets.xml")
  end
  
  def children
    self.class.find(:all, :from => "/folders/#{id.to_s}/children.xml")
  end
  
  def parent
    return unless parent?
    self.class.find(parent_id)
    # self.class.find(:one, :from => "/folders/#{id.to_s}/parent")
  end
  
  def parent?
    self.parent_id? && self.parent_id.to_i != 0
  end
  
  def email(to, subject, msg)
    self.post(:email, :to => to, :subject => subject, :msg => msg)
  end
  
  def ancestors
    self.class.find(:all, :from => "/folders/#{id.to_s}/ancestors.xml")
  end
end